package com.itheima.health.resource.aliyunmessage;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.itheima.health.resource.date.DateUtils;

import javax.xml.crypto.Data;
import java.util.Date;

/**
 * 短信发送工具类
 */
public class SMSUtils {

	public  static  String accessKeyId = "LTAI4G875FYE6gKNN3GQh2uz";
	public  static String accessKeySecret = "xXSqidCMq9dcLBc9vBPUc79PmJHpny";

	public static  String VALIDATE_CODE = "SMS_200713125";//发送短信验证码
	public static  String ORDER_NOTICE = "SMS_201450746";//体检预约成功通知


	/**
	 *   注册短信发送
	 */
	public static void validaCodeSms(String telephone,String randomCode) {
		DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
		IAcsClient client = new DefaultAcsClient(profile);

		CommonRequest request = new CommonRequest();
		request.setSysMethod(MethodType.POST);
		request.setSysDomain("dysmsapi.aliyuncs.com");
		request.setSysVersion("2017-05-25");
		request.setSysAction("SendSms");
		request.putQueryParameter("RegionId", "cn-hangzhou");
		request.putQueryParameter("PhoneNumbers", telephone);
		request.putQueryParameter("SignName", "代码果实能力者");
		request.putQueryParameter("TemplateCode", VALIDATE_CODE);
		request.putQueryParameter("TemplateParam", "{\"code\":\""+randomCode+"\"}");
		try {
			CommonResponse response = client.getCommonResponse(request);
			System.out.println(response.getData());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}


	/**
	 * 预约套餐成功 发送短信通知
	 */
	public static void sendMessageTuYou(String telephone,String message){


		DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
		IAcsClient client = new DefaultAcsClient(profile);

		CommonRequest request = new CommonRequest();
		request.setSysMethod(MethodType.POST);
		request.setSysDomain("dysmsapi.aliyuncs.com");
		request.setSysVersion("2017-05-25");
		request.setSysAction("SendSms");
		request.putQueryParameter("RegionId", "cn-hangzhou");
		request.putQueryParameter("PhoneNumbers", telephone);
		request.putQueryParameter("SignName", "代码果实能力者");
		request.putQueryParameter("TemplateCode", ORDER_NOTICE);
		request.putQueryParameter("TemplateParam", "{\"submittime\":\""+message+"\"}");
		try {
			CommonResponse response = client.getCommonResponse(request);
			System.out.println(response.getData());
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
